<%#
name: kickstart_networking_setup
model: ProvisioningTemplate
snippet: true
kind: snippet
-%>
<%- bonded_interfaces = [] -%>
<%- bonding_interfaces = [] -%>
<%- @host.bond_interfaces.each do |bond| -%>
<%-   bonding_interfaces.push(bond.identifier) -%>
<%=   "# #{bond.identifier} interface" %>
<%=   snippet('kickstart_ifcfg_get_identifier_names', :variables => { :identifier => bond.identifier }) %>
<%-   ifcfg = snippet('kickstart_ifcfg_bond_interface', :variables => {
                        :interface => bond,
                        :subnet => bond.subnet,
                        :subnet6 => bond.subnet6,
                        :dhcp => bond.subnet.nil? ? false : bond.subnet.dhcp_boot_mode? }) -%>
<%=   save_to_file('/etc/sysconfig/network-scripts/ifcfg-$sanitized_real', ifcfg) %>

<%-   @host.interfaces_with_identifier(bond.attached_devices_identifiers).each do |interface| -%>
<%-     next if !interface.managed? -%>
<%=     "# #{interface.identifier} interface" %>
<%=     snippet('kickstart_ifcfg_get_identifier_names', :variables => { :interface => interface }) -%>
<%-     ifcfg = snippet('kickstart_ifcfg_bonded_interface', :variables => {
                          :interface => interface,
                          :subnet => interface.subnet,
                          :subnet6 => interface.subnet6,
                          :dhcp => false,
                          :bond_identifier => bond.identifier }) %>
<%=     save_to_file('/etc/sysconfig/network-scripts/ifcfg-$sanitized_real', ifcfg) %>
<%-     bonded_interfaces.push(interface.identifier) %>
<%-   end -%>
<%- end -%>

<%- @host.managed_interfaces.each do |interface| %>
<%-   next if !interface.managed? -%>
<%-   next if bonded_interfaces.include?(interface.identifier) -%>

<%-   interface_identifier = @host.bond_interfaces.map { |i| i.identifier }.include?(interface.attached_to) ? interface.identifier : nil %>
<%=   "# #{interface.identifier} interface" %>
<%=   snippet('kickstart_ifcfg_get_identifier_names', :variables => { :interface => interface, :identifier => interface_identifier }) -%>
<%-   ifcfg = snippet('kickstart_ifcfg_generic_interface', :variables => {
                        :interface => interface,
                        :subnet => interface.subnet,
                        :subnet6 => interface.subnet6,
                        :bonding_interfaces => bonding_interfaces,
                        :dhcp => interface.subnet.nil? ? false : interface.subnet.dhcp_boot_mode?,
                        :attached_to_bond => interface_identifier.present? }) %>
<%=   save_to_file('/etc/sysconfig/network-scripts/ifcfg-$sanitized_real', ifcfg) %>
<%- end %>
